package com.db.controller;

import com.db.common.pojo.TreeNode;
import com.db.pojo.SysDept;
import com.db.service.SysDeptService;
import com.db.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dept/")
public class SysDeptController {

	@Autowired
	private SysDeptService sysDeptService;

	@RequestMapping("doFindObjects")
	public SysResult doFindObjects() {
		List<Map<String, Object>> list = sysDeptService.findObjects();
		return new SysResult(list);
	}

	@RequestMapping("doDeleteObject")
	public SysResult doDeleteObject(Integer id) {
		sysDeptService.deleteById(id);
		return new SysResult("delete ok");
	}

	@RequestMapping("doFindZTreeNodes")
	public SysResult doFindZTreeNodes() {
		List<TreeNode> treeNodes = sysDeptService.findTree();
		return new SysResult(treeNodes);
	}

	@RequestMapping("doSaveObject")
	public SysResult doSaveObject(SysDept sysDept) {
		sysDeptService.insertObject(sysDept);
		return new SysResult("save ok");
	}

	@RequestMapping("doUpdateObject")
	public SysResult doUpdateObject(SysDept sysDept) {
		sysDeptService.updateObject(sysDept);
		return new SysResult("update ok");
	}
}
